﻿///<reference path="_references.js" />

var TJBlog = {};

TJBlog.RichText = {
    _load: function () {
        $("#rich-content").markItUp(mySettings);
    },
    _enablePreview: function () {
        var html = $("#rich-content").val();
        $("#rich-preview").html(html);
        $("#rich-preview").val(html);
        $("#rich-preview").find("pre").each(function (idx, item) { SyntaxHighlighter.highlight({}, item); });
    },
    _formatCode: function () {
        SyntaxHighlighter.all();
    }
}

TJBlog.Initializer = {
    _loadAll: function () {
        this._loadSlider();
        this._loadStyles();
        this._loadEventBinding();
    },
    _loadSlider: function () {
        $('#slider-main').nivoSlider({
            effect: 'fade',
            animSpeed: 500,
            pauseTime: 3000,
            startSlide: 0, // Set starting Slide (0 index)
            directionNav: true, // Next & Prev navigation
            prevText: 'Prev', // Prev directionNav text
            nextText: 'Next', // Next directionNav text
            controlNav: true, // 1,2,3... navigation
            controlNavThumbs: false, // Use thumbnails for Control Nav
            pauseOnHover: true, // Stop animation while hovering
            manualAdvance: false // Force manual transitions
        });
    },
    _loadStyles: function () {
        var submitBtn = $(".submit-button");
        $(".submit-button").hover(function (event) {
            submitBtn.css("background-color", "#3b7cb4");
            submitBtn.css("color", "#fff");
        }, function (event) {
            submitBtn.css("background-color", "#e6e6e6");
            submitBtn.css("color", "#333");
        });
        $("a.button").each(function (idx, item) {
            $(item).hover(function () {
                $(item).css("background-color", "#e6e6e6");
            }, function () {
                $(item).css("background-color", "#f0f1f4");
            })
        });
    },
    _loadEventBinding: function () {
        $(".login").each(function (n, t) {
            $(t).click(function () {
                window.open(root + "Account/ExternalLogin?provider=" + $(t).attr("data-provider"), "_blank", "width=400,height=500,resizable=yes")
            })
        });
    }
}


TJBlog.AjaxLoader = {
    _loadArticleList: function () {
        $.ajax({
            url: root + "Home/LatestArticles",
            success: function (data, status, jqXHR) { $("#all-articles").empty(); $("#all-articles").append(data); },
            error: function (data, status, jqXHR) { $("#all-articles").append("Some error ocurrs... ;("); }
        });
    }
}
